﻿using PacketRush.Services.Commanding;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PacketRush.Core;

namespace PacketRush.Services.Commanding.Test
{
    
    
    /// <summary>
    ///This is a test class for ClientCommandServiceTest and is intended
    ///to contain all ClientCommandServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ClientCommandServiceTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for ExecuteCommand
        ///</summary>
        [TestMethod()]
        public void ExecuteCommandTest()
        {
            ClientCommandService clientCommandSvc = new ClientCommandService();
            ServerCommandService serverCommandSvc = new ServerCommandService();

            TestCommand command = new TestCommand();
            command.Execute += new System.EventHandler<CommandEventArgs>(ExecuteCommandTest_Execute);

            // Add command to both client and server
            clientCommandSvc.AddCommand(command);
            serverCommandSvc.AddCommand(command);

            // Test the command running on the client
            clientCommandSvc.ExecuteCommand("testcommand -o \"foo, bar, bat\" -x 50.55 -y 50%", false);

            // Test the command on the server
            clientCommandSvc.ExecuteCommand("testcommand -o \"foo, bar, bat\" -x 50.55 -y 50%", true);
            serverCommandSvc.DeliverPacket(clientCommandSvc.CollectPacket());
        }

        void ExecuteCommandTest_Execute(object sender, CommandEventArgs e)
        {
            Assert.AreEqual(e.Command.CommandName, new TestCommand().CommandName);
            Assert.AreEqual(e.Args.Length, 6);
        }

        ///// <summary>
        /////A test for DeliverPacket
        /////</summary>
        //[TestMethod()]
        //public void DeliverPacketTest()
        //{
        //    ClientCommandService target = new ClientCommandService(); // TODO: Initialize to an appropriate value
        //    Packet packet = null; // TODO: Initialize to an appropriate value
        //    target.DeliverPacket(packet);
        //    Assert.Inconclusive("A method that does not return a value cannot be verified.");
        //}

        ///// <summary>
        /////A test for CollectPacket
        /////</summary>
        //[TestMethod()]
        //public void CollectPacketTest()
        //{
        //    ClientCommandService target = new ClientCommandService(); // TODO: Initialize to an appropriate value
        //    Packet expected = null; // TODO: Initialize to an appropriate value
        //    Packet actual;
        //    actual = target.CollectPacket();
        //    Assert.AreEqual(expected, actual);
        //    Assert.Inconclusive("Verify the correctness of this test method.");
        //}
    }
}
